import 'package:continue_downloader/continue_downloader.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  ContinueDownloader downloader = ContinueDownloader();

  int receivedBytes = 0;
  int totalBytes = 0;
  var url = "";
  var savePath = "";
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('ContinueDownloader')),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                onPressed: () {
                  downloader.startDownload(
                      url: url,
                      savePath: savePath,
                      process: (c, t) {
                        receivedBytes = c;
                        totalBytes = t;
                        setState(() {});
                      });
                },
                child: const Text('start download'),
              ),
              const SizedBox(height: 20),
              Text(
                'now: $receivedBytes / $totalBytes bytes',
                style: const TextStyle(fontSize: 18),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                onPressed: () {
                  downloader.close();
                },
                child: const Text('pause'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
